package com.itheima.tliaswebmanagement.controller;

import com.itheima.tliaswebmanagement.pojo.common.Result;
import com.itheima.tliaswebmanagement.utils.AliyunOSSUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description UploadController
 * @Author ziguan ling
 * @Date 2025--01--08
 */
@Slf4j
@RestController
public class UploadController {
    @Autowired
    AliyunOSSUtil aliyunOSSUtil;

    /**
     * spring框架提供了MultipartFile接收前端文件资源数据‘
     * MultipartFile：接收用户上传的资源文件，暂存到服务器磁盘指定的位置
     *                请求处理完毕，自动清空上传的资源文件
     */
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
        log.info("文件上传");
        String fileUrl = aliyunOSSUtil.upload(file);
        return Result.success(fileUrl);
    }
}
